package com.kalenchuk.ui;

import javax.annotation.PostConstruct;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

import org.springframework.beans.factory.annotation.Autowired;

import com.kalenchuk.service.TransformatorService;
import com.kalenchuk.service.WireService;
import com.kalenchuk.ui.combo.BranchTypeComboBox;
import com.kalenchuk.ui.table.BranchTableModel;

public class MainAppWin extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7773154151013590365L;
	
	@Autowired
	private WireService wireService;
	
	@Autowired
	private TransformatorService transformatorService;
	/**
	 * Creates new form NewJFrame
	 */
	public MainAppWin() {
	

	}

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">  
    @PostConstruct
    private void initComponents() {

        wirePopupMenu = new javax.swing.JPopupMenu();
        wireDeleteMenuItem = new javax.swing.JMenuItem();
        nodesPopupMenu = new javax.swing.JPopupMenu();
        nodeDeleteMenuItem = new javax.swing.JMenuItem();
        branchPopupMenu = new javax.swing.JPopupMenu();
        branchDeleteMenuItem = new javax.swing.JMenuItem();
        transformatorPopupMenu = new javax.swing.JPopupMenu();
        transformatorDeleteMenuItem = new javax.swing.JMenuItem();
        toolBarPanel = new javax.swing.JPanel();
        buttonNew = new javax.swing.JButton();
        buttonLoad = new javax.swing.JButton();
        buttonSave = new javax.swing.JButton();
        buttonAnalize = new javax.swing.JButton();
        tablesPanel = new javax.swing.JTabbedPane();
        nodesTab = new javax.swing.JPanel();
        nodesScrollPane = new javax.swing.JScrollPane();
        nodesTable = new javax.swing.JTable();
        numberSearchFilter = new javax.swing.JTextField();
        pSearchFilter = new javax.swing.JTextField();
        qSearchFilter = new javax.swing.JTextField();
        branchesTab = new javax.swing.JPanel();
        branchesScrollPane = new javax.swing.JScrollPane();
        branchesTable = new javax.swing.JTable();
        startSearchFilter = new javax.swing.JTextField();
        endSearchFilter = new javax.swing.JTextField();
        rSearchFilter = new javax.swing.JTextField();
        xSearchFilter = new javax.swing.JTextField();
        wireTab = new javax.swing.JPanel();
        wireScrollPane = new javax.swing.JScrollPane();
        wireTable = new javax.swing.JTable();
        brandSearchFilter = new javax.swing.JTextField();
        r0SearchFilter = new javax.swing.JTextField();
        x0SearchFilter = new javax.swing.JTextField();
        currentSearchFilter = new javax.swing.JTextField();
        transformatorTab = new javax.swing.JPanel();
        transformerScrollPane = new javax.swing.JScrollPane();
        transformetTable = new javax.swing.JTable();
        transformerTypeSearchField = new javax.swing.JTextField();
        sNormSearchField = new javax.swing.JTextField();
        ukSearchField = new javax.swing.JTextField();
        pkSearchField = new javax.swing.JTextField();
        uNormSearchField = new javax.swing.JTextField();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newMenuItem = new javax.swing.JMenuItem();
        loadMenuItem = new javax.swing.JMenuItem();
        saveItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutAppMenuItem = new javax.swing.JMenuItem();

        wirePopupMenu.setName("wirePopupMenu"); // NOI18N

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("Bundle"); // NOI18N
        wireDeleteMenuItem.setText(bundle.getString("MainAppWin.wireDeleteMenuItem.text")); // NOI18N
        wireDeleteMenuItem.setName("wireDeleteMenuItem"); // NOI18N
        wireDeleteMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wireDeleteMenuItemActionPerformed(evt);
            }
        });
        wirePopupMenu.add(wireDeleteMenuItem);

        nodesPopupMenu.setName("nodesPopupMenu"); // NOI18N

        nodeDeleteMenuItem.setText(bundle.getString("MainAppWin.nodeDeleteMenuItem.text")); // NOI18N
        nodeDeleteMenuItem.setName("nodeDeleteMenuItem"); // NOI18N
        nodeDeleteMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nodeDeleteMenuItemActionPerformed(evt);
            }
        });
        nodesPopupMenu.add(nodeDeleteMenuItem);

        branchPopupMenu.setName("branchPopupMenu"); // NOI18N

        branchDeleteMenuItem.setText(bundle.getString("MainAppWin.branchDeleteMenuItem.text")); // NOI18N
        branchDeleteMenuItem.setName("branchDeleteMenuItem"); // NOI18N
        branchDeleteMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                branchDeleteMenuItemActionPerformed(evt);
            }
        });
        branchPopupMenu.add(branchDeleteMenuItem);

        transformatorPopupMenu.setName("transformatorPopupMenu"); // NOI18N

        transformatorDeleteMenuItem.setText(bundle.getString("MainAppWin.transformatorDeleteMenuItem.text")); // NOI18N
        transformatorDeleteMenuItem.setName("transformatorDeleteMenuItem"); // NOI18N
        transformatorDeleteMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transformatorDeleteMenuItemActionPerformed(evt);
            }
        });
        transformatorPopupMenu.add(transformatorDeleteMenuItem);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle(bundle.getString("MainAppWin.title")); // NOI18N
        setName("Form"); // NOI18N

        toolBarPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        toolBarPanel.setName("toolBarPanel"); // NOI18N

        buttonNew.setText(bundle.getString("MainAppWin.buttonNew.text")); // NOI18N
        buttonNew.setFocusable(false);
        buttonNew.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNew.setName("buttonNew"); // NOI18N
        buttonNew.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNewActionPerformed(evt);
            }
        });

        buttonLoad.setText(bundle.getString("MainAppWin.buttonLoad.text")); // NOI18N
        buttonLoad.setFocusable(false);
        buttonLoad.setName("buttonLoad"); // NOI18N
        buttonLoad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonLoadActionPerformed(evt);
            }
        });

        buttonSave.setText(bundle.getString("MainAppWin.buttonSave.text")); // NOI18N
        buttonSave.setFocusable(false);
        buttonSave.setName("buttonSave"); // NOI18N
        buttonSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSaveActionPerformed(evt);
            }
        });

        buttonAnalize.setText(bundle.getString("MainAppWin.buttonAnalize.text")); // NOI18N
        buttonAnalize.setFocusable(false);
        buttonAnalize.setName("buttonAnalize"); // NOI18N
        buttonAnalize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAnalizeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout toolBarPanelLayout = new javax.swing.GroupLayout(toolBarPanel);
        toolBarPanel.setLayout(toolBarPanelLayout);
        toolBarPanelLayout.setHorizontalGroup(
            toolBarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolBarPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(buttonNew)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonLoad)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonSave)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonAnalize)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        toolBarPanelLayout.setVerticalGroup(
            toolBarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, toolBarPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(toolBarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(toolBarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(buttonLoad)
                        .addComponent(buttonSave)
                        .addComponent(buttonAnalize))
                    .addComponent(buttonNew))
                .addContainerGap())
        );

        tablesPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        tablesPanel.setName("tablesPanel"); // NOI18N

        nodesTab.setName("nodesTab"); // NOI18N

        nodesScrollPane.setName("nodesScrollPane"); // NOI18N

        nodesTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Number", "P", "Q"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        nodesTable.setFillsViewportHeight(true);
        nodesTable.setName("nodesTable"); // NOI18N
        nodesTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                nodesTableMouseClicked(evt);
            }
        });
        nodesTable.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                nodesTableCaretPositionChanged(evt);
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                nodesTableInputMethodTextChanged(evt);
            }
        });
        nodesTable.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                nodesTablePropertyChange(evt);
            }
        });
        nodesTable.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                nodesTableVetoableChange(evt);
            }
        });
        nodesScrollPane.setViewportView(nodesTable);

        numberSearchFilter.setName("numberSearchFilter"); // NOI18N

        pSearchFilter.setName("pSearchFilter"); // NOI18N

        qSearchFilter.setName("qSearchFilter"); // NOI18N

        javax.swing.GroupLayout nodesTabLayout = new javax.swing.GroupLayout(nodesTab);
        nodesTab.setLayout(nodesTabLayout);
        nodesTabLayout.setHorizontalGroup(
            nodesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(nodesTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(nodesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(nodesScrollPane)
                    .addGroup(nodesTabLayout.createSequentialGroup()
                        .addComponent(numberSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(qSearchFilter, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)))
                .addContainerGap())
        );
        nodesTabLayout.setVerticalGroup(
            nodesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, nodesTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(nodesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(numberSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(qSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nodesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 507, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        tablesPanel.addTab(bundle.getString("MainAppWin.nodesTab.TabConstraints.tabTitle"), nodesTab); // NOI18N

        branchesTab.setName("branchesTab"); // NOI18N

        branchesScrollPane.setName("branchesScrollPane"); // NOI18N

        branchesTable.setModel(new BranchTableModel());
        
        branchesTable.setFillsViewportHeight(true);
        branchesTable.setName("branchesTable"); // NOI18N
        branchesTable.getTableHeader().setReorderingAllowed(false);
        branchesTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                branchesTableMouseClicked(evt);
            }
        });
        branchesTable.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                branchesTablePropertyChange(evt);
            }
        });
        
        
        TableColumn column = branchesTable.getColumnModel().getColumn(2);
        column.setCellEditor(new DefaultCellEditor(new BranchTypeComboBox()));
        
        branchesScrollPane.setViewportView(branchesTable);
        if (branchesTable.getColumnModel().getColumnCount() > 0) {
            
        	branchesTable.getColumnModel().getColumn(0).setHeaderValue(bundle.getString("MainAppWin.branchesTable.columnModel.title0")); // NOI18N
            branchesTable.getColumnModel().getColumn(1).setHeaderValue(bundle.getString("MainAppWin.branchesTable.columnModel.title1")); // NOI18N
            branchesTable.getColumnModel().getColumn(2).setHeaderValue(bundle.getString("MainAppWin.branchesTable.columnModel.title2")); // NOI18N
            branchesTable.getColumnModel().getColumn(3).setHeaderValue(bundle.getString("MainAppWin.branchesTable.columnModel.title3")); // NOI18N
            branchesTable.getColumnModel().getColumn(4).setHeaderValue(bundle.getString("MainAppWin.branchesTable.columnModel.title4")); // NOI18N
            branchesTable.getColumnModel().getColumn(5).setHeaderValue(bundle.getString("MainAppWin.branchesTable.columnModel.title5")); // NOI18N
            branchesTable.getColumnModel().getColumn(6).setHeaderValue(bundle.getString("MainAppWin.branchesTable.columnModel.title6")); // NOI18N
            branchesTable.getColumnModel().getColumn(6).setMinWidth(0);
            branchesTable.getColumnModel().getColumn(6).setPreferredWidth(0);
            branchesTable.getColumnModel().getColumn(6).setMaxWidth(0);
            
        }

        startSearchFilter.setName("startSearchFilter"); // NOI18N

        endSearchFilter.setName("endSearchFilter"); // NOI18N

        rSearchFilter.setName("rSearchFilter"); // NOI18N
        rSearchFilter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rSearchFilterActionPerformed(evt);
            }
        });

        xSearchFilter.setName("xSearchFilter"); // NOI18N

        javax.swing.GroupLayout branchesTabLayout = new javax.swing.GroupLayout(branchesTab);
        branchesTab.setLayout(branchesTabLayout);
        branchesTabLayout.setHorizontalGroup(
            branchesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(branchesTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(branchesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(branchesScrollPane)
                    .addGroup(branchesTabLayout.createSequentialGroup()
                        .addComponent(startSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(endSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(xSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        branchesTabLayout.setVerticalGroup(
            branchesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(branchesTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(branchesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(startSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(endSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(xSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(branchesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 502, Short.MAX_VALUE)
                .addContainerGap())
        );

        tablesPanel.addTab(bundle.getString("MainAppWin.branchesTab.TabConstraints.tabTitle"), branchesTab); // NOI18N

        wireTab.setName("wireTab"); // NOI18N

        wireScrollPane.setBackground(new java.awt.Color(255, 255, 255));
        wireScrollPane.setAutoscrolls(true);
        wireScrollPane.setName("wireScrollPane"); // NOI18N

        wireTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null}
            },
            new String [] {
                "Brand", "R0", "X0", "Max I", ""
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Long.class
            };
            boolean[] canEdit = new boolean [] {
                true, true, true, true, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        wireService.fillWireTable(wireTable);
        wireTable.setName("wireTable"); // NOI18N
        wireTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                wireTableMouseClicked(evt);
            }
        });
        wireTable.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                wireTablePropertyChange(evt);
            }
        });
        wireScrollPane.setViewportView(wireTable);
        if (wireTable.getColumnModel().getColumnCount() > 0) {
            wireTable.getColumnModel().getColumn(0).setHeaderValue(bundle.getString("MainAppWin.wireTable.columnModel.title0")); // NOI18N
            wireTable.getColumnModel().getColumn(1).setHeaderValue(bundle.getString("MainAppWin.wireTable.columnModel.title1")); // NOI18N
            wireTable.getColumnModel().getColumn(2).setResizable(false);
            wireTable.getColumnModel().getColumn(2).setHeaderValue(bundle.getString("MainAppWin.wireTable.columnModel.title2")); // NOI18N
            wireTable.getColumnModel().getColumn(3).setHeaderValue(bundle.getString("MainAppWin.wireTable.columnModel.title3")); // NOI18N
            wireTable.getColumnModel().getColumn(4).setMinWidth(0);
            wireTable.getColumnModel().getColumn(4).setPreferredWidth(0);
            wireTable.getColumnModel().getColumn(4).setMaxWidth(0);
            wireTable.getColumnModel().getColumn(4).setHeaderValue(bundle.getString("MainAppWin.wireTable.columnModel.title4")); // NOI18N
        }

        brandSearchFilter.setName("brandSearchFilter"); // NOI18N

        r0SearchFilter.setName("r0SearchFilter"); // NOI18N
        r0SearchFilter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r0SearchFilterActionPerformed(evt);
            }
        });

        x0SearchFilter.setName("x0SearchFilter"); // NOI18N

        currentSearchFilter.setName("currentSearchFilter"); // NOI18N

        javax.swing.GroupLayout wireTabLayout = new javax.swing.GroupLayout(wireTab);
        wireTab.setLayout(wireTabLayout);
        wireTabLayout.setHorizontalGroup(
            wireTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(wireTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(wireTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(wireScrollPane)
                    .addGroup(wireTabLayout.createSequentialGroup()
                        .addComponent(brandSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(r0SearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(x0SearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(currentSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        wireTabLayout.setVerticalGroup(
            wireTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(wireTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(wireTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(brandSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(r0SearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(x0SearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(currentSearchFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(wireScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 502, Short.MAX_VALUE)
                .addContainerGap())
        );

        tablesPanel.addTab(bundle.getString("MainAppWin.wireTab.TabConstraints.tabTitle"), wireTab); // NOI18N

        transformatorTab.setName("transformatorTab"); // NOI18N

        transformerScrollPane.setName("transformerScrollPane"); // NOI18N

        transformetTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null}
            },
            new String [] {
                "Type", "Snorm", "Uk", "Pk", "Unorm, kV", ""
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Long.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        transformatorService.fillTransformatorTable(transformetTable);
        transformetTable.setName("transformetTable"); // NOI18N
        transformetTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                transformetTableMouseClicked(evt);
            }
        });
        transformetTable.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                transformetTablePropertyChange(evt);
            }
        });
        transformerScrollPane.setViewportView(transformetTable);
        if (transformetTable.getColumnModel().getColumnCount() > 0) {
            transformetTable.getColumnModel().getColumn(0).setHeaderValue(bundle.getString("MainAppWin.transformetTable.columnModel.title0")); // NOI18N
            transformetTable.getColumnModel().getColumn(1).setHeaderValue(bundle.getString("MainAppWin.transformetTable.columnModel.title1")); // NOI18N
            transformetTable.getColumnModel().getColumn(2).setHeaderValue(bundle.getString("MainAppWin.transformetTable.columnModel.title2")); // NOI18N
            transformetTable.getColumnModel().getColumn(3).setHeaderValue(bundle.getString("MainAppWin.transformetTable.columnModel.title3")); // NOI18N
            transformetTable.getColumnModel().getColumn(4).setHeaderValue(bundle.getString("MainAppWin.transformetTable.columnModel.title4")); // NOI18N
            transformetTable.getColumnModel().getColumn(5).setHeaderValue(bundle.getString("MainAppWin.transformetTable.columnModel.title5")); // NOI18N
            transformetTable.getColumnModel().getColumn(5).setMinWidth(0);
            transformetTable.getColumnModel().getColumn(5).setPreferredWidth(0);
            transformetTable.getColumnModel().getColumn(5).setMaxWidth(0);
        }

        transformerTypeSearchField.setName("transformerTypeSearchField"); // NOI18N
        transformerTypeSearchField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transformerTypeSearchFieldActionPerformed(evt);
            }
        });

        sNormSearchField.setName("sNormSearchField"); // NOI18N
        sNormSearchField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sNormSearchFieldActionPerformed(evt);
            }
        });

        ukSearchField.setName("ukSearchField"); // NOI18N
        ukSearchField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ukSearchFieldActionPerformed(evt);
            }
        });

        pkSearchField.setName("pkSearchField"); // NOI18N
        pkSearchField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pkSearchFieldActionPerformed(evt);
            }
        });

        uNormSearchField.setName("uNormSearchField"); // NOI18N
        uNormSearchField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uNormSearchFieldActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout transformatorTabLayout = new javax.swing.GroupLayout(transformatorTab);
        transformatorTab.setLayout(transformatorTabLayout);
        transformatorTabLayout.setHorizontalGroup(
            transformatorTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(transformatorTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(transformatorTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(transformerScrollPane)
                    .addGroup(transformatorTabLayout.createSequentialGroup()
                        .addComponent(transformerTypeSearchField, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sNormSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ukSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pkSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(uNormSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        transformatorTabLayout.setVerticalGroup(
            transformatorTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, transformatorTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(transformatorTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(transformerTypeSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sNormSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ukSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pkSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(uNormSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(transformerScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 502, Short.MAX_VALUE)
                .addContainerGap())
        );

        tablesPanel.addTab(bundle.getString("MainAppWin.transformatorTab.TabConstraints.tabTitle"), transformatorTab); // NOI18N

        menuBar.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        menuBar.setMinimumSize(new java.awt.Dimension(50, 2));
        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(bundle.getString("MainAppWin.fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N
        fileMenu.setPreferredSize(new java.awt.Dimension(50, 19));

        newMenuItem.setText(bundle.getString("MainAppWin.newMenuItem.text")); // NOI18N
        newMenuItem.setMinimumSize(new java.awt.Dimension(50, 0));
        newMenuItem.setName("newMenuItem"); // NOI18N
        newMenuItem.setPreferredSize(new java.awt.Dimension(150, 22));
        newMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(newMenuItem);

        loadMenuItem.setText(bundle.getString("MainAppWin.loadMenuItem.text")); // NOI18N
        loadMenuItem.setName("loadMenuItem"); // NOI18N
        loadMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(loadMenuItem);

        saveItem.setText(bundle.getString("MainAppWin.saveItem.text")); // NOI18N
        saveItem.setName("saveItem"); // NOI18N
        saveItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveItem);

        exitMenuItem.setText(bundle.getString("MainAppWin.exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(bundle.getString("MainAppWin.helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N
        helpMenu.setPreferredSize(new java.awt.Dimension(50, 19));

        aboutAppMenuItem.setText(bundle.getString("MainAppWin.aboutAppMenuItem.text")); // NOI18N
        aboutAppMenuItem.setName("aboutAppMenuItem"); // NOI18N
        aboutAppMenuItem.setPreferredSize(new java.awt.Dimension(150, 22));
        helpMenu.add(aboutAppMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(toolBarPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(tablesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addComponent(toolBarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tablesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 584, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
        setVisible(true);
    }// </editor-fold>                        

    private void buttonAnalizeActionPerformed(java.awt.event.ActionEvent evt) {                                              
    }                                             

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                             
        System.out.println("Implement close programm functionality, pleases");
    }                                            

    private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {                                           
    }                                          

    private void saveItemActionPerformed(java.awt.event.ActionEvent evt) {                                         
    }                                        

    private void loadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                             
    }                                            

    private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                            
    }                                           

    private void buttonLoadActionPerformed(java.awt.event.ActionEvent evt) {                                           
    }                                          

    private void buttonNewActionPerformed(java.awt.event.ActionEvent evt) {                                          
    }                                         

    private void uNormSearchFieldActionPerformed(java.awt.event.ActionEvent evt) {                                                 
    }                                                

    private void pkSearchFieldActionPerformed(java.awt.event.ActionEvent evt) {                                              
    }                                             

    private void ukSearchFieldActionPerformed(java.awt.event.ActionEvent evt) {                                              
    }                                             

    private void sNormSearchFieldActionPerformed(java.awt.event.ActionEvent evt) {                                                 
    }                                                

    private void transformerTypeSearchFieldActionPerformed(java.awt.event.ActionEvent evt) {                                                           
        // TODO add your handling code here:
    }                                                          

    private void rSearchFilterActionPerformed(java.awt.event.ActionEvent evt) {                                              
    }                                             

    private void nodesTableVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {                                          
    }                                         

    private void nodesTablePropertyChange(java.beans.PropertyChangeEvent evt) {                                          
        if(evt.getPropertyName().equals("tableCellEditor")) {
            int selectedRowPosition = nodesTable.getSelectedRow();
            int rowCount = nodesTable.getModel().getRowCount();
            if(rowCount == selectedRowPosition+1) {
                Object [] arr = {null, null, null};
                ((DefaultTableModel)nodesTable.getModel()).addRow(arr);
            }
        }
    }                                         

    private void nodesTableCaretPositionChanged(java.awt.event.InputMethodEvent evt) {                                                
    }                                               

    private void nodesTableInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {                                                  
    }                                                 

    private void wireTableMouseClicked(java.awt.event.MouseEvent evt) {                                       
        if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
            int selectedRowPosition = wireTable.getSelectedRow();
            if(selectedRowPosition != -1) {
              wirePopupMenu.show(wireTable, evt.getX(), evt.getY());
          }
          
}
    }                                      

	private void wireDeleteMenuItemActionPerformed(
			java.awt.event.ActionEvent evt) {
		int selectedRowPosition = wireTable.getSelectedRow();
		if (selectedRowPosition != -1) {
			Long id = (Long) wireTable.getValueAt(selectedRowPosition, wireTable.getColumnCount() - 1);
			wireService.deleteWire(id);
			((DefaultTableModel) wireTable.getModel()).removeRow(selectedRowPosition);
		}
	}                                                  

    private void nodesTableMouseClicked(java.awt.event.MouseEvent evt) {                                        
        if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
            int selectedRowPosition = nodesTable.getSelectedRow();
            if (selectedRowPosition != -1) {
                nodesPopupMenu.show(nodesTable, evt.getX(), evt.getY());
            }
        }
    }                                       

    private void branchesTableMouseClicked(java.awt.event.MouseEvent evt) {                                           
        if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
            int selectedRowPosition = branchesTable.getSelectedRow();
            if (selectedRowPosition != -1) {
                branchPopupMenu.show(branchesTable, evt.getX(), evt.getY());
            }
        }
    }    
    
    private void branchesTablePropertyChange(java.beans.PropertyChangeEvent evt) {                                          
        if(evt.getPropertyName().equals("tableCellEditor")) {
            int selectedRowPosition = branchesTable.getSelectedRow();
            int rowCount = branchesTable.getModel().getRowCount();
            if(rowCount == selectedRowPosition+1) {
            	JComboBox branchTypeCombobox = new BranchTypeComboBox();
            	
                Object [] arr = {null, null, branchTypeCombobox, null, null, null, null};
                ((DefaultTableModel)nodesTable.getModel()).addRow(arr);
            }
        }
    }                                         

    private void transformetTableMouseClicked(java.awt.event.MouseEvent evt) {                                              
        if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
            int selectedRowPosition = transformetTable.getSelectedRow();
            if (selectedRowPosition != -1) {
                transformatorPopupMenu.show(transformetTable, evt.getX(), evt.getY());
            }
        }
    }                                             

    private void nodeDeleteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        int selectedRowPosition = nodesTable.getSelectedRow();
        if(selectedRowPosition != -1) {
            ((DefaultTableModel)nodesTable.getModel()).removeRow(selectedRowPosition);
        }
    }                                                  

    private void branchDeleteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                                     
        int selectedRowPosition = branchesTable.getSelectedRow();
        if(selectedRowPosition != -1) {
            ((DefaultTableModel)branchesTable.getModel()).removeRow(selectedRowPosition);
        }
    }                                                    

    private void transformatorDeleteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                                            
        int selectedRowPosition = transformetTable.getSelectedRow();
        if(selectedRowPosition != -1) {
        	Long id = (Long) wireTable.getValueAt(selectedRowPosition, wireTable.getColumnCount() - 1);
			wireService.deleteWire(id);
            ((DefaultTableModel)transformetTable.getModel()).removeRow(selectedRowPosition);
        }
    }                                                           

    private void r0SearchFilterActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
    }                                              

    private void wireTablePropertyChange(java.beans.PropertyChangeEvent evt) {                                         
        if(evt.getPropertyName().equals("tableCellEditor")) {
            int selectedRowPosition = wireTable.getSelectedRow();
            int rowCount = wireTable.getModel().getRowCount();
            
            boolean isLastRowChanged = rowCount == selectedRowPosition+1;
            if(isLastRowChanged) {
                Object [] arr = new Object[wireTable.getColumnCount()];
                ((DefaultTableModel)wireTable.getModel()).addRow(arr);
            }
            
            
            Long id = (Long)wireTable.getValueAt(selectedRowPosition, wireTable.getColumnCount()-1);
			if (id != null) {
				wireService.updateWire(id,
						(String)wireTable.getValueAt(selectedRowPosition, 0),
						(Double)wireTable.getValueAt(selectedRowPosition, 1),
						(Double)wireTable.getValueAt(selectedRowPosition, 2),
						(Double)wireTable.getValueAt(selectedRowPosition, 3));
			} else {
				//Save
				id = wireService.saveWire(
						(String)wireTable.getValueAt(selectedRowPosition, 0),
						(Double)wireTable.getValueAt(selectedRowPosition, 1),
						(Double)wireTable.getValueAt(selectedRowPosition, 2),
						(Double)wireTable.getValueAt(selectedRowPosition, 3));
				//update UI
				wireTable.setValueAt(id, selectedRowPosition, wireTable.getColumnCount()-1);
				
			}
            
        }
    }                                        

    private void transformetTablePropertyChange(java.beans.PropertyChangeEvent evt) {                                                
         if(evt.getPropertyName().equals("tableCellEditor")) {
            int selectedRowPosition = transformetTable.getSelectedRow();
            int rowCount = transformetTable.getModel().getRowCount();
            if(rowCount == selectedRowPosition+1) {
                Object [] arr = {null, null, null, null, null};
                ((DefaultTableModel)transformetTable.getModel()).addRow(arr);
            }
        }
         
         
         
         if(evt.getPropertyName().equals("tableCellEditor")) {
             int selectedRowPosition = transformetTable.getSelectedRow();
             int rowCount = transformetTable.getModel().getRowCount();
             
             boolean isLastRowChanged = rowCount == selectedRowPosition+1;
             if(isLastRowChanged) {
                 Object [] arr = new Object[transformetTable.getColumnCount()];
                 ((DefaultTableModel)transformetTable.getModel()).addRow(arr);
             }
             
             
            Long id = (Long)transformetTable.getValueAt(selectedRowPosition, transformetTable.getColumnCount()-1);
 			if (id != null) {
 				transformatorService.updateTransformator(id,
 						(String)transformetTable.getValueAt(selectedRowPosition, 0),
 						(Double)transformetTable.getValueAt(selectedRowPosition, 1),
 						(Double)transformetTable.getValueAt(selectedRowPosition, 2),
 						(Double)transformetTable.getValueAt(selectedRowPosition, 3),
 						(Double)transformetTable.getValueAt(selectedRowPosition, 4));
 			} else {
 				//Save
 				id = transformatorService.saveTransformator(
 						(String)transformetTable.getValueAt(selectedRowPosition, 0),
 						(Double)transformetTable.getValueAt(selectedRowPosition, 1),
 						(Double)transformetTable.getValueAt(selectedRowPosition, 2),
 						(Double)transformetTable.getValueAt(selectedRowPosition, 3),
 						(Double)transformetTable.getValueAt(selectedRowPosition, 4));
 				//update UI
 				transformetTable.setValueAt(id, selectedRowPosition, transformetTable.getColumnCount()-1);
 				
 			}
             
         }
    }                                               

    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        System.out.println("TEST");
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainAppWin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainAppWin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainAppWin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainAppWin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                
                new MainAppWin().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JMenuItem aboutAppMenuItem;
    private javax.swing.JMenuItem branchDeleteMenuItem;
    private javax.swing.JPopupMenu branchPopupMenu;
    private javax.swing.JScrollPane branchesScrollPane;
    private javax.swing.JPanel branchesTab;
    private javax.swing.JTable branchesTable;
    private javax.swing.JTextField brandSearchFilter;
    private javax.swing.JButton buttonAnalize;
    private javax.swing.JButton buttonLoad;
    private javax.swing.JButton buttonNew;
    private javax.swing.JButton buttonSave;
    private javax.swing.JTextField currentSearchFilter;
    private javax.swing.JTextField endSearchFilter;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JMenuItem loadMenuItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem newMenuItem;
    private javax.swing.JMenuItem nodeDeleteMenuItem;
    private javax.swing.JPopupMenu nodesPopupMenu;
    private javax.swing.JScrollPane nodesScrollPane;
    private javax.swing.JPanel nodesTab;
    private javax.swing.JTable nodesTable;
    private javax.swing.JTextField numberSearchFilter;
    private javax.swing.JTextField pSearchFilter;
    private javax.swing.JTextField pkSearchField;
    private javax.swing.JTextField qSearchFilter;
    private javax.swing.JTextField r0SearchFilter;
    private javax.swing.JTextField rSearchFilter;
    private javax.swing.JTextField sNormSearchField;
    private javax.swing.JMenuItem saveItem;
    private javax.swing.JTextField startSearchFilter;
    private javax.swing.JTabbedPane tablesPanel;
    private javax.swing.JPanel toolBarPanel;
    private javax.swing.JMenuItem transformatorDeleteMenuItem;
    private javax.swing.JPopupMenu transformatorPopupMenu;
    private javax.swing.JPanel transformatorTab;
    private javax.swing.JScrollPane transformerScrollPane;
    private javax.swing.JTextField transformerTypeSearchField;
    private javax.swing.JTable transformetTable;
    private javax.swing.JTextField uNormSearchField;
    private javax.swing.JTextField ukSearchField;
    private javax.swing.JMenuItem wireDeleteMenuItem;
    private javax.swing.JPopupMenu wirePopupMenu;
    private javax.swing.JScrollPane wireScrollPane;
    private javax.swing.JPanel wireTab;
    private javax.swing.JTable wireTable;
    private javax.swing.JTextField x0SearchFilter;
    private javax.swing.JTextField xSearchFilter;
    // End of variables declaration                   

}
